<?php

namespace App\Models\Shop\Goods;

use App\Models\Common\CommonModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class GoodsClassify extends CommonModel
{
    use HasFactory;
    protected $table = 'goods_classify';
    public function moreChildren() {
        return $this->hasMany(GoodsClassify::class,'pid','id')->orderBy('sort','desc');
    }

    public function children() {
        return $this->moreChildren()->with(['children']);
    }

    public function getRecords(array $conditions) {
        $records = parent::getRecords($conditions); // TODO: Change the autogenerated stub
        if(isset($conditions['pid'])){
            $records = $records->where('pid',$conditions['pid']);
        }
        return $records;
    }

    public function getGrandFather() {
        return $this->getRecordById($this->pid)->first();
    }


}
